package com.example.mygrade.service.impl;

import com.example.mygrade.domain.Student;
import com.example.mygrade.domain.TeacherMa;
import com.example.mygrade.exception.REnum;
import com.example.mygrade.exception.RException;
import com.example.mygrade.repository.StudentRepository;
import com.example.mygrade.repository.TeacherMaRepository;
import com.example.mygrade.service.TeacherMaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class TeacherMaImplService implements TeacherMaService {
    @Autowired
    private TeacherMaRepository teacherMaRepository;
    public List<TeacherMa> findByMnameAndMpass(String name, String password) throws Exception{
        List<TeacherMa> bySnameAndPassword = teacherMaRepository.findByMnameAndMpass(name,password);
//        if (bySnameAndPassword.size() > 0){
//            return bySnameAndPassword;
//        }else {
//            throw  new RException(REnum.LOGIN_ERR);

        return bySnameAndPassword;
    }

    public List<TeacherMa> findAll(){
        return teacherMaRepository.findAll();
    }

    public TeacherMa findByMnameLike(String userName){
        return teacherMaRepository.findByMnameLike(userName);
    }

    public  TeacherMa update(TeacherMa teacherMa){
        return teacherMaRepository.save(teacherMa);
    }
}
